package com.example.designpattern.proxy.jdk;


import com.example.designpattern.proxy.staticProxy.MySubject;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class MyInvocationHandler implements InvocationHandler {
    private final MySubject mySubject;

    public MyInvocationHandler(MySubject mySubject) {
        this.mySubject = mySubject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String name = method.getName();
        System.out.println("代理做事");
        if (name.equals("doSomething"))
            return method.invoke(mySubject, args);
        else
            return method.invoke(mySubject, args);
    }
}
